<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 给你一份 JS 代码，应该可以看得懂
      const objArr = [
        { name: '柯基', age: 3, male: true },
        { name: '布偶', age: 2, male: false },
        { name: '走地鸡', age: 4, male: true },
        { name: '金鱼', age: 5, male: false },
      ]

      // 数组方法 find，findIndex,filter,reduce,map...
      // find 找到符合条件的第一个，找到之后就不再继续检索，节约性能
      const obj = objArr.find(v => v.male === false)
      console.log(obj)

      const index = objArr.findIndex(v => v.male === false)
      console.log(index)

      // filter 找不到，返回的也是一个数组，空数组(true)
      // const arr = objArr.filter(v => v.age >= 4)
      const arr = objArr.filter(v => v.age >= 6)
      console.log(arr)

      // reduce
      const result = objArr.reduce((prev, cur) => {
        return prev + cur.age
      }, 0)
      console.log(result)

      // map 映射方法基于数组 A 生成数组B
      const newArr = objArr.map(v => {
        return v.age
      })
      console.log(newArr)

      // Math
      // Date
      // 定时器
      // Promise
      // RegExp(正则对象)
      // ...
    </script>
  </body>
</html>
